<?php
namespace voxfa\net;

use voxfa\net\core;

use voxfa\net\store\NetworkInterfaceFactory;
use voxfa\net\core\NetworkInterfaceSupport;

class NetworkInterface {
	
	protected $displayName;
	protected $name;
	protected $attrs = array();
	
	protected $inetAddresses;
	
	protected $support;
	
	public function __construct(){
		$this->support = new NetworkinterfaceSupport();
	}
	
	public function getDisplayName(){
		return $this->displayName;
	}
	
	public function setDisplayName($displayName){
		$this->displayName = $displayName;
	}
	
	public function getName(){
		return $this->name;
	}
	
	public function setName($name){
		$this->name = $name;
	}
	
	/**
	 * 获得接口上的地址
	 */
	public function getInetAddresses(){
		if($this->inetAddresses == null)
			$this->inetAddresses = InetAddress::getByName($this->name);
		return $this->inetAddresses;
	}
	
	public function getAttribute($key){
		if (array_key_exists($key,$this->attrs))
			return $this->attrs[$key];
		return null;
	}
	
	public function setAttribute($key,$value){
		$this->attrs[$key]=$value;	
	}
	
	public function getAttributes(){
		return $this->attrs;
	}
	
	public function setAttributes($attrs){
		$this->attrs = $attrs;
	}
	
	/**
	 * save networkinterface
	 */
	public function save(){
		return $this->support->save($this);
	}
	
	public function remove(){
		return $this->support->remove($this->name);
	}
	
	public static function getNetworkInterfaces(){
		return $this->support->getNetworkInterfaces();
	}
	
	public static function getByInetAddress(InetAddress $address) {
		$address = InetAddress::getByAddress($address);
		return self::getByName($address->getName());
	}
	
	public static function getByName($interfaceName) {
		return $this->support->getByName();
	}
	
	public function __toString(){
		
	}
}

